
var sendSms = function() {
    var time = DateFormat.format.date(new Date(), 'yyyyMMddHHmmssSSS');
    var sign = SparkMD5.hash(SID + time + TOKEN);
    api.ajax({
        url: SERVER_URL + '/entity/employer/sms',
        method: 'post',
        timeout: 30,
        dataType: 'json',
        returnAll: false,
        data: {
            values: {
                phone: $api.dom('#phone').value
            }
        }
    }, function(ret, err) {
        if (ret) {
            var urlJson = JSON.stringify(ret);
            api.alert({
                msg: urlJson
            });
        } else {
            api.alert({
                msg: ('错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode)
            });
        };
    });
};
var getToken = function() {
    api.ajax({
        url: SERVER_URL + '/entity/auth/token',
        method: 'put',
        timeout: 30,
        dataType: 'json',
        returnAll: false,
        data: {
            values: {
                phone: $api.dom('#phone').value,
                password: $api.dom('#code').value,
                type: 'employer'
            }
        }
    }, function(ret, err) {
        if (ret) {
            api.setPrefs({
                key: 'token',
                value: ret.token
            });

			api.execScript({
				name : api["pageParam"]['loginPage'],
				script : 'loginBack();'
			});
			window.closeWin();
        } else {
            api.alert({
                msg: ('错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode)
            });
        };
    });
};
var apiready = function() {
    /* 一个获取导航栏高度的方法. */
    window.getNavHeight = function() {
        var h = 44;

        if ("ios" == api.systemType && parseInt(api.systemVersion) >= 7) {
            h = 64;
        }
        return h;
    }

    /* 一个关闭窗口,返回上一级页面的优雅实现. */
    window.closeWin = function(winName) {
        api.closeWin();
    }

    // -----------------------------------------
    /* 导航栏自适应iOS 7. */
    var header = $api.byId('header');
    $api.fixIos7Bar(header);

    /* Android,点击返回键,可以返回上一级. */
    window.addEventListener("keyback", function() {
        window.addEventListener("keyback", function() {
            if (!api["pageParam"]["isFrame"]) { // 仅在是主窗口时,才捕捉 keyback事件.
                window.closeWin();
            }
        });
    });
};
